package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishItemVO;
import com.sky.vo.DishOverViewVO;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/dish")
@Api(tags = "菜品管理")
@Slf4j
public class DishController {

    @Autowired
    private DishService dishService;

    @GetMapping("/page")
    @ApiOperation("分页查询菜品")
    public Result<PageResult> page(DishPageQueryDTO dto){
        log.info("分页查询菜品: {}", dto);
        PageResult pageResult = dishService.page(dto);
        return Result.success(pageResult);
    }

    @ApiOperation("起售停售菜品")
    @PostMapping("/status/{status}")
    public Result status(@PathVariable("status") Integer status, @RequestParam Long id){
        log.info("起售停售菜品: {}, {}", status, id);
        dishService.status(status, id);
        return Result.success();
    }

    @ApiOperation("批量删除菜品")
    @DeleteMapping()
    public Result delete(@RequestParam("ids") String ids){
        log.info("批量删除菜品: {}", ids);
        dishService.delete(ids);
        return Result.success();
    }

    @ApiOperation("新增菜品")
    @PostMapping()
    public Result add(@RequestBody DishDTO dishDTO){
        log.info("新增菜品");
        dishService.add(dishDTO);
        return Result.success();
    }

    @ApiOperation("根据ID查询菜品")
    @GetMapping("/{id}")
    public Result<DishVO> get(@PathVariable("id") Long id){
        log.info("根据ID查询菜品: {}", id);
        DishVO dishVO = dishService.getById(id);
        return Result.success(dishVO);

    }

    @ApiOperation("修改菜品")
    @PutMapping()
    public Result update(@RequestBody DishDTO dishDTO){
        log.info("修改菜品");
       dishService.update(dishDTO);
        return Result.success();
    }

    @ApiOperation("根据分类ID查询菜品")
    @GetMapping("/list")
    public Result<List<Dish>> list(@RequestParam("categoryId") Integer categoryId){
        log.info("根据分类ID查询菜品: {}", categoryId);
        List<Dish> dishList = dishService.listByCategoryId(categoryId);
        return Result.success(dishList);

    }

}
